package com.runvp.netty.server.handler;


import com.runvp.common.model.tcp.MessageReceiveBody;
import com.runvp.common.model.tcp.MessageResBody;
import com.runvp.netty.build.BuildHttpClint;
import com.runvp.netty.constant.NettyConstant;
import com.runvp.service.tcp.TcpService;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;


/**
 * 设备发送基本信息包 -设备自主发起
 */
@Slf4j
public class DeviceReportBaseInfoHandle extends BizHandle{

    private MessageReceiveBody parseBody;

    private TcpService tcpService;

    public DeviceReportBaseInfoHandle(TcpService tcpService, MessageReceiveBody parseBody){
        this.parseBody = parseBody;
        this.tcpService = tcpService;
    }
    /**
     * 设备发送基本信息包
     */
    public MessageResBody handle(Channel channel){
        long st = System.currentTimeMillis();
        try{
            //线程执行
//            DeviceReportBaseIfoRunnable runnable = new DeviceReportBaseIfoRunnable(channel,tcpService,parseBody);
//            ThreadPoolActuator.exeTask(runnable);
//            return runnable.defaultRes();
            String sn = NettyConstant.allOnlineChannleIds.get(NettyConstant.getChannelId(channel));
            log.info("设备基本信息上报处理sn: {}",sn);
            parseBody.setTerminalId(sn);
            return BuildHttpClint.postJson("/app/cmd/report",parseBody);
        }finally {
            log.info("本次设备基本信息上报响应时间:【{} ms】",(System.currentTimeMillis()-st));
        }
    }


}
